package com.ytjj.qmyx.admin.service.impl;

import com.github.pagehelper.PageHelper;
import com.ytjj.common.api.CommonPage;
import com.ytjj.qmyx.admin.dao.UsersCouponDao;
import com.ytjj.qmyx.admin.dao.UsersCouponRelationDao;
import com.ytjj.qmyx.admin.model.UsersCoupon;
import com.ytjj.qmyx.admin.model.request.UsersCouponRelationRequest;
import com.ytjj.qmyx.admin.model.request.UsersCouponRequest;
import com.ytjj.qmyx.admin.service.UsersCouponService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UsersCouponServiceImpl implements UsersCouponService {

    @Autowired
    private UsersCouponDao usersCouponDao;

    @Autowired
    private UsersCouponRelationDao usersCouponRelationDao;

    @Override
    public CommonPage<UsersCoupon> getList(UsersCouponRequest usersCouponRequest) {
        PageHelper.startPage(usersCouponRequest.getPageNum(), usersCouponRequest.getPageSize());
        List<UsersCoupon> list = usersCouponDao.selectList(usersCouponRequest);
        return CommonPage.restPage(list);
    }

    @Override
    public int insertRelation(UsersCouponRelationRequest ucrRequest) {
        int count = 0;
        for (int i = 0; i<ucrRequest.getCouponCount(); i++) {
            System.out.println("===============" + ucrRequest.getUsersId());
            System.out.println("===============" + ucrRequest.getUsersCouponId());
            count = usersCouponRelationDao.insertRelation(ucrRequest.getUsersId(), ucrRequest.getUsersCouponId());
        }
        return count;
    }

}
